// PollutionAnalysisMapper.java
package com.chinasoft.pollution_analysis.mapper;

import com.chinasoft.pollution_analysis.entity.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PollutionAnalysisMapper {

    // 全国污染物平均浓度
    @Select("SELECT * FROM national_avg_concentration")
    List<PollutionStats> selectNationalAvg();

    // 区域污染物浓度
    @Select("SELECT * FROM regional_concentration WHERE city = #{city}")
    List<RegionalStats> selectRegionalByCity(String city);

    @Select("SELECT * FROM regional_concentration")
    List<RegionalStats> selectRegionalAll();

    // 时间趋势分析
    @Select("SELECT * FROM hourly_trend WHERE pollutant_type = #{pollutantType}")
    List<TimeTrend> selectHourlyTrendByPollutant(String pollutantType);

    @Select("SELECT * FROM hourly_trend")
    List<TimeTrend> selectHourlyTrendAll();

    @Select("SELECT * FROM daily_trend WHERE pollutant_type = #{pollutantType}")
    List<TimeTrend> selectDailyTrendByPollutant(String pollutantType);

    @Select("SELECT * FROM daily_trend")
    List<TimeTrend> selectDailyTrendAll();

    // 城市污染排名
    @Select("SELECT * FROM city_pollution_ranking WHERE pollutant_type = #{pollutantType} LIMIT #{limit}")
    List<CityRanking> selectCityRankingByPollutant(@Param("pollutantType") String pollutantType,
                                                   @Param("limit") Integer limit);

    @Select("SELECT * FROM city_pollution_ranking LIMIT #{limit}")
    List<CityRanking> selectCityRankingAll(Integer limit);

    // 重点城市分析
    @Select("SELECT * FROM key_city_analysis")
    List<RegionalStats> selectKeyCityAnalysis();

    // 污染物分布
    @Select("SELECT * FROM pollutant_distribution")
    List<PollutantDistribution> selectPollutantDistribution();

    // 热点分析
    @Select("SELECT * FROM hourly_spatial_temporal WHERE date_value = #{date} AND region = #{region}")
    List<HotspotAnalysis> selectHotspotByDateAndRegion(@Param("date") String date,
                                                       @Param("region") String region);

    @Select("SELECT * FROM hourly_spatial_temporal")
    List<HotspotAnalysis> selectHotspotAll();

    // 时空趋势
    @Select("SELECT * FROM spatio_temporal_trend WHERE region = #{region} AND season = #{season}")
    List<SpatioTemporalTrend> selectSpatioTemporalTrend(@Param("region") String region,
                                                        @Param("season") String season);

    @Select("SELECT * FROM spatio_temporal_trend")
    List<SpatioTemporalTrend> selectSpatioTemporalTrendAll();

    // 统计数据
    @Select("SELECT COUNT(DISTINCT city) as cities_count FROM regional_concentration")
    Integer selectCitiesCount();

    @Select("SELECT COUNT(DISTINCT pollutant_type) as pollutants_count FROM national_avg_concentration")
    Integer selectPollutantsCount();

    @Select("SELECT SUM(sample_count) as total_records FROM national_avg_concentration")
    Long selectTotalRecords();

    // 新增的方法 - 解决编译错误
    @Select("SELECT DISTINCT pollutant_type FROM national_avg_concentration ORDER BY pollutant_type")
    List<String> selectPollutantTypes();

    @Select("SELECT DISTINCT city FROM regional_concentration WHERE city IS NOT NULL ORDER BY city")
    List<String> selectCityList();
}